package com.microsight.wuyou

import android.app.ActivityManager
import android.content.Context
import android.os.Build
import android.os.Process
import android.webkit.WebView
import androidx.annotation.RequiresApi
import androidx.multidex.MultiDex
import io.flutter.app.FlutterApplication

/**
 * Class description:
 *
 * @version 1.0
 */
class JJApplication : FlutterApplication(){
    @RequiresApi(Build.VERSION_CODES.P)
    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(this)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            val processName = getProcessName(this)
            val packageName = this.packageName
            if (packageName != processName) {
                WebView.setDataDirectorySuffix(processName!!)
            }
        }
    }

    override fun onCreate() {
        super.onCreate()
    }

    private fun getProcessName(context: Context?): String? {
        if (context == null) return null
        val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        for (processInfo in manager.runningAppProcesses) {
            if (processInfo.pid == Process.myPid()) {
                return processInfo.processName
            }
        }
        return null
    }


}